﻿/**
* ...
* @author Default
* @version 0.1
*/

package bdz.projects.slab.renderers {
	import as3.common.ui.menu.core.MenuComponent;
	import as3.common.ui.menu.core.MenuItem;
	import as3.projects.slfi.data.ExhibitVO;
	import as3.projects.slfi.data.ArtistVO;
	import bdz.dms.vo.SectionVO;
	//
	import as3.common.ui.menu.events.MenuComponentEvent;
	import flash.display.MovieClip;
	import flash.display.SimpleButton;
	import flash.events.Event;
	import as3.common.utils.BitmapUtils;
	import flash.text.*;
	import as3.common.display.bdzImage;
	import flash.utils.*;
	import bdz.common.model.AppEnvironment;
	import flash.events.MouseEvent;
	public class GalleryByMonth extends MenuItem{
		private var settings:AppEnvironment;
		private var vo:SectionVO;
		//
		private var viewDets:SimpleButton;
		private var blackBG:MovieClip;
		private var dateField:TextField;
		private var imageDisplay:bdzImage;
		private var artistField:TextField;
		private var titleField:TextField;
		private var virtualWidth:Number = 130;
		private var virtualBG:MovieClip;
		//
		function GalleryByMonth(tstyle:Object,frm:TextFormat,sv:String=null){
			super(tstyle, frm, sv);
			settings = AppEnvironment.getEnv();
			addEventListener(Event.ADDED_TO_STAGE, initializeComponent);
		}
		override protected function createField():void{
			
		}
		private function prepareText(field:TextField):void{
			var menuFontFormat:TextFormat = new TextFormat();
			var fontObj:Object = getDefinitionByName("pixelate");
			menuFontFormat.color = 0x555555;
			menuFontFormat.font = new fontObj().fontName;
			menuFontFormat.size = 10;
			field.autoSize = "left";
			field.antiAliasType = AntiAliasType.NORMAL;
			field.gridFitType = GridFitType.PIXEL;
			field.setTextFormat(menuFontFormat);
			field.defaultTextFormat = menuFontFormat;
			field.selectable = false;
			field.embedFonts = true;
			field.autoSize = "left";
			field.width = virtualWidth;
			field.wordWrap = true;
			field.multiline = true;
		}
		private function initializeComponent(evt:Event):void{
			
			virtualBG = new MovieClip();
			super.createBounds(virtualBG, virtualWidth, 10, 0);
			addChild(virtualBG);
			virtualBG.cacheAsBitmap = true;
			blackBG = new MovieClip();
			//blackBG.y = dateField.y+dateField.height+5;
			addChild(blackBG);
			blackBG.cacheAsBitmap = true;
			imageDisplay = new bdzImage();
			imageDisplay.y = blackBG.y + 5;
			imageDisplay.x = blackBG.x + 5;
			addChild(imageDisplay);
			imageDisplay.cacheAsBitmap = true;
			imageDisplay.buttonMode = true;
			imageDisplay.useHandCursor = true;
			try{
				imageDisplay.source = settings.getSetting("baseURL")+vo.getProperty("default_image");
			}catch(e:Error){
				
			}
			try {
				super.createBounds(blackBG, Number(vo.getProperty("default_image_width"))+10, Number(vo.getProperty("default_image_height"))+10, 1);
				
			}catch(e:Error){
				trace("error on black bg");
			}
			artistField = new TextField();
			prepareText(artistField);
			
			if(vo.getProperty("artist_list") != ""){
				try{
					var len:Number = vo.getProperty("artist_list").split(",").length;
					var i:Number = -1;
					while(i++<len){
						artistField.appendText(vo.getProperty("artist_list").split(",")[i].toUpperCase() + "\n");
					}			
				}catch(e:Error){
					
				}
			}
			artistField.cacheAsBitmap = true;
			artistField.textColor = 0x7d7d7d;
			addChild(artistField);
			artistField.y = Math.ceil(blackBG.y+blackBG.height+5);
			
			
			titleField = new TextField();
			prepareText(titleField);
			titleField.cacheAsBitmap = true;
			titleField.textColor = 0x4c4c4c;
			titleField.text = vo.section_name.toUpperCase();
			titleField.y = Math.ceil(artistField.y+artistField.height+5);
						
			
			addChild(titleField);
			
			viewDets = new detailsButton();
			viewDets.addEventListener(MouseEvent.CLICK, itemClicked);
			imageDisplay.addEventListener(MouseEvent.CLICK, itemClicked);
			viewDets.y = titleField.y+titleField.height+15;
			addChild(viewDets);
			
		}
		override protected function itemClicked(evt:MouseEvent):void{
			dispatchEvent(new MenuComponentEvent(MenuComponentEvent.CLICK, vo));
		}
		
		override public function get fieldWidth():Number{
			return virtualWidth;
		}
		override public function get fieldHeight():Number{
			return 10;
		}
		override public function set info(inf:*):void{
			vo = inf as SectionVO;
		}
		override public function get info():*{
			return vo;
		}
		
		
	}
	
}